<script lang="ts" setup>
import { getParkCarListAPI } from '@/apis/billingRules';
import type { ParkCar, ParkCarListParams } from '@/types/billingRules';
import { ref } from 'vue';

const list = ref<ParkCar[]>([])

const params = ref<ParkCarListParams>({
  page: 1,
  pageSize: 10,
  carNumber: '',
  paymentStatus: ''
})

const total = ref(0)
const getList = async () => {

  const res = await getParkCarListAPI(params.value)
  console.log('res',res)
  list.value = res.data.rows
  total.value = res.data.total
}
getList()

// 支付方式处理函数
const handlePaymentMethod = (item: ParkCar) => {
  // console.log('item',item)
  if(item.paymentMethod === 'Alipay'){
    return '支付宝'
  }else if(item.paymentMethod === 'WeChat'){
    return '微信'
  }else if(item.paymentMethod === 'Cash'){
    return '线下'
  }else{
    return '--'
  }
  
}
const onSearch = () => {
  params.value.page = 1
  getList()
}

</script>

<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">车牌号码：</span>
      <el-input clearable placeholder="请输入内容" @clear="onSearch" v-model="params.carNumber" class="search-main" />
      <span class="search-label">缴纳状态：</span>
      <el-select style="width: 240px" v-model="params.paymentStatus">
        <el-option label="全部" value="" />
        <el-option label="待缴纳" value="0" />
        <el-option label="已缴纳" value="1" />
      </el-select>
      <el-button type="primary" class="search-btn" @click="onSearch">查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="list">
        <el-table-column type="index" label="序号" width="100" />
        <el-table-column prop="carNumber" label="车牌号码" />
        <el-table-column prop="chargeType" label="收费类型">
          <template #default="scope">
            {{ scope.row.chargeType === 'card' ? '月卡' : '临时停车' }}
          </template>
        </el-table-column>
        <el-table-column prop="parkingTime" label="停车总时长" />
        <el-table-column prop="actualCharge" label="缴纳费用(元)" />
        <el-table-column prop="paymentStatus" label="缴纳状态">
          <template #default="scope">
            {{ scope.row.paymentStatus === 0 ? '未缴纳' : '已缴纳' }}
          </template>
        </el-table-column>
        <el-table-column prop="paymentMethod" label="缴纳方式">
          <template #default="scope">
            {{ handlePaymentMethod(scope.row) }}
          </template>
        </el-table-column>
        <el-table-column prop="paymentTime" label="缴纳时间" width="180" />
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container" style="display: flex;justify-content: end;">
      <el-pagination 
      layout="total, prev, pager, next, sizes, jumper" 
      :page-sizes="[2, 5, 10, 20, 100]"
      :total="total"
      v-model:current-page="params.page" 
      v-model:page-size="params.pageSize"
      @change="getList()"
       />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}

.create-container {
  margin: 10px 0px;
}

.page-container {
  padding: 4px 0px;
  text-align: right;
}

.form-container {
  padding: 0px 80px;
}
</style>